<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/murmur/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/murmur/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/murmur/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/murmur/images/logo.svg" color="#222">

<link rel="stylesheet" href="/murmur/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/murmur/","scheme":"Gemini","version":"8.0.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"disqus","storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}};
  </script>

  <meta name="description" content="实现自动轮播的环图，并添加鼠标悬停的事件控制">
<meta property="og:type" content="article">
<meta property="og:title" content="ECharts实现环图轮播以及事件控制">
<meta property="og:url" content="https://gitee.com/lianghuilin/murmur.git/echarts/ECharts%E5%AE%9E%E7%8E%B0%E7%8E%AF%E5%9B%BE%E8%BD%AE%E6%92%AD%E4%BB%A5%E5%8F%8A%E4%BA%8B%E4%BB%B6%E6%8E%A7%E5%88%B6/index.html">
<meta property="og:site_name" content="汇话板">
<meta property="og:description" content="实现自动轮播的环图，并添加鼠标悬停的事件控制">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-07-04T12:30:12.000Z">
<meta property="article:modified_time" content="2021-11-27T00:16:54.807Z">
<meta property="article:author" content="William Leung">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://gitee.com/lianghuilin/murmur.git/echarts/ECharts%E5%AE%9E%E7%8E%B0%E7%8E%AF%E5%9B%BE%E8%BD%AE%E6%92%AD%E4%BB%A5%E5%8F%8A%E4%BA%8B%E4%BB%B6%E6%8E%A7%E5%88%B6/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ECharts实现环图轮播以及事件控制 | 汇话板</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?a49081c570a782a242cdf6e19e1a584d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/murmur/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">汇话板</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">设定目标，放慢步调，用温和的力量自我改革</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/murmur/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/murmur/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%80%E7%BB%88%E6%95%88%E6%9E%9C"><span class="nav-number">1.</span> <span class="nav-text">最终效果</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%9D%E8%B7%AF"><span class="nav-number">2.</span> <span class="nav-text">思路</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81"><span class="nav-number">3.</span> <span class="nav-text">完整代码</span></a></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">William Leung</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/murmur/archives">
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">文章</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/murmur/categories/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/murmur/tags/">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </section>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/lianghuilin/murmur.git/echarts/ECharts%E5%AE%9E%E7%8E%B0%E7%8E%AF%E5%9B%BE%E8%BD%AE%E6%92%AD%E4%BB%A5%E5%8F%8A%E4%BA%8B%E4%BB%B6%E6%8E%A7%E5%88%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/murmur/images/avatar.gif">
      <meta itemprop="name" content="William Leung">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="汇话板">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ECharts实现环图轮播以及事件控制
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-07-04 20:30:12" itemprop="dateCreated datePublished" datetime="2021-07-04T20:30:12+08:00">2021-07-04</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-11-27 08:16:54" itemprop="dateModified" datetime="2021-11-27T08:16:54+08:00">2021-11-27</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/murmur/categories/%E5%8F%AF%E8%A7%86%E5%8C%96%E5%86%85%E5%8F%82/" itemprop="url" rel="index"><span itemprop="name">可视化内参</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>3 分钟</span>
    </span>
</div>

            <div class="post-description">实现自动轮播的环图，并添加鼠标悬停的事件控制</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="最终效果"><a href="#最终效果" class="headerlink" title="最终效果"></a>最终效果</h2><script async src="//jsrun.net/JIUKp/embed/html,result/light"></script>

<h2 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h2><ol>
<li>环图是饼图的变形，通过配置<code>series.radius: [内半径, 外半径]</code>设置环图；</li>
<li>再通过<code>series.label = &#123; position: &#39;center&#39;, show: false &#125;</code>将各项数据的label放到圆的中心；</li>
<li>echarts通过<code>dispatchAction</code>方法触发图表的行为，设置默认选中的数据</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">chartInstance.dispatchAction(&#123;</span><br><span class="line">    type: <span class="string">&#x27;highlight&#x27;</span>, <span class="comment">// 高亮即选中</span></span><br><span class="line">    seriesIndex: <span class="number">0</span>, <span class="comment">// 第一组数据</span></span><br><span class="line">    dataIndex: index    <span class="comment">// 第几项数据</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>监听鼠标悬停/离开，进行数据的选中/取消选中</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">chartInstance.on(<span class="string">&#x27;mouseover&#x27;</span>, <span class="function"><span class="params">params</span> =&gt;</span> &#123;</span><br><span class="line">    chartInstance.dispatchAction(&#123;</span><br><span class="line">        type: <span class="string">&#x27;highlight&#x27;</span>,</span><br><span class="line">        seriesIndex: <span class="number">0</span>,</span><br><span class="line">        dataIndex: hoverIndex</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="5">
<li>通过<code>setInterval</code>轮询调用<code>dispatchAction</code> API，按数据下标实现自动轮播</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> isHover = <span class="literal">false</span></span><br><span class="line"><span class="keyword">let</span> hoverIndex = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 立即执行的轮询器</span></span><br><span class="line"><span class="keyword">const</span> setIntervalNow = <span class="function">(<span class="params">fn, time</span>) =&gt;</span> &#123;</span><br><span class="line">    fn()</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">setInterval</span>(fn, time)</span><br><span class="line">&#125;  </span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> loop = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 如果鼠标悬停状态，则跳过逻辑</span></span><br><span class="line">    <span class="keyword">if</span>(isHover) <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line">    myChart.dispatchAction(&#123;</span><br><span class="line">        type: <span class="string">&#x27;downplay&#x27;</span>,</span><br><span class="line">        seriesIndex: <span class="number">0</span>,</span><br><span class="line">        dataIndex: hoverIndex</span><br><span class="line">    &#125;)</span><br><span class="line"></span><br><span class="line">    hoverIndex++</span><br><span class="line">    <span class="keyword">if</span>(hoverIndex &gt; dataList.length - <span class="number">1</span>)&#123;</span><br><span class="line">        hoverIndex = <span class="number">0</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    myChart.dispatchAction(&#123;</span><br><span class="line">        type: <span class="string">&#x27;highlight&#x27;</span>,</span><br><span class="line">        seriesIndex: <span class="number">0</span>,</span><br><span class="line">        dataIndex: hoverIndex</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">setIntervalNow(loop, <span class="number">1000</span>)</span><br></pre></td></tr></table></figure>

<h2 id="完整代码"><a href="#完整代码" class="headerlink" title="完整代码"></a>完整代码</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>第一个 ECharts 实例<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 引入 echarts.js --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 为ECharts准备一个具备大小（宽高）的Dom --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;main&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 600px;height:400px;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="comment">// 基于准备好的dom，初始化echarts实例</span></span></span><br><span class="line"><span class="javascript">        <span class="keyword">var</span> myChart = echarts.init(<span class="built_in">document</span>.getElementById(<span class="string">&#x27;main&#x27;</span>));</span></span><br><span class="line"> </span><br><span class="line"><span class="javascript">        <span class="comment">// 数据源</span></span></span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> dataList = [</span></span><br><span class="line"><span class="javascript">            &#123; <span class="attr">value</span>: <span class="number">1048</span>, <span class="attr">name</span>: <span class="string">&#x27;JavaScript&#x27;</span> &#125;,</span></span><br><span class="line"><span class="javascript">            &#123; <span class="attr">value</span>: <span class="number">735</span>, <span class="attr">name</span>: <span class="string">&#x27;HTML&#x27;</span> &#125;,</span></span><br><span class="line"><span class="javascript">            &#123; <span class="attr">value</span>: <span class="number">580</span>, <span class="attr">name</span>: <span class="string">&#x27;CSS&#x27;</span> &#125;,</span></span><br><span class="line"><span class="javascript">            &#123; <span class="attr">value</span>: <span class="number">484</span>, <span class="attr">name</span>: <span class="string">&#x27;Vue.js&#x27;</span> &#125;,</span></span><br><span class="line"><span class="javascript">            &#123; <span class="attr">value</span>: <span class="number">300</span>, <span class="attr">name</span>: <span class="string">&#x27;React.js&#x27;</span> &#125;</span></span><br><span class="line">        ]</span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="comment">// 指定图表的配置项和数据</span></span></span><br><span class="line"><span class="javascript">        <span class="keyword">var</span> option = &#123;</span></span><br><span class="line">            tooltip: &#123;</span><br><span class="line"><span class="javascript">                trigger: <span class="string">&#x27;item&#x27;</span></span></span><br><span class="line">            &#125;,</span><br><span class="line">            legend: &#123;</span><br><span class="line"><span class="javascript">                top: <span class="string">&#x27;5%&#x27;</span>,</span></span><br><span class="line"><span class="javascript">                selectedMode: <span class="literal">false</span></span></span><br><span class="line">            &#125;,</span><br><span class="line">            series: [</span><br><span class="line">                &#123;</span><br><span class="line"><span class="javascript">                    type: <span class="string">&#x27;pie&#x27;</span>,</span></span><br><span class="line"><span class="javascript">                    radius: [<span class="string">&#x27;50%&#x27;</span>, <span class="string">&#x27;70%&#x27;</span>],</span></span><br><span class="line">                    label: &#123;</span><br><span class="line"><span class="javascript">                        position: <span class="string">&#x27;center&#x27;</span>,</span></span><br><span class="line"><span class="javascript">                        show: <span class="literal">false</span></span></span><br><span class="line">                    &#125;,</span><br><span class="line">                    emphasis: &#123;</span><br><span class="line">                        label: &#123;</span><br><span class="line"><span class="javascript">                            show: <span class="literal">true</span>,</span></span><br><span class="line"><span class="javascript">                            fontSize: <span class="string">&#x27;22&#x27;</span>,</span></span><br><span class="line"><span class="javascript">                            fontWeight: <span class="string">&#x27;bold&#x27;</span>,</span></span><br><span class="line"><span class="javascript">                            formatter: <span class="string">&#x27;&#123;b&#125;\n&#123;c&#125;&#x27;</span></span></span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;,</span><br><span class="line">                    data: dataList</span><br><span class="line">                &#125;</span><br><span class="line">            ]</span><br><span class="line">        &#125;;</span><br><span class="line"> </span><br><span class="line"><span class="javascript">        <span class="comment">// 使用刚指定的配置项和数据显示图表。</span></span></span><br><span class="line">        myChart.setOption(option);</span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="comment">// 事件监听</span></span></span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> hoverIndex = <span class="number">0</span></span></span><br><span class="line">        myChart.dispatchAction(&#123;</span><br><span class="line"><span class="javascript">            type: <span class="string">&#x27;highlight&#x27;</span>,</span></span><br><span class="line">            seriesIndex: 0,</span><br><span class="line">            dataIndex: hoverIndex</span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="comment">// 实现轮播</span></span></span><br><span class="line">            </span><br><span class="line"></span><br><span class="line"><span class="javascript">        myChart.on(<span class="string">&#x27;mouseover&#x27;</span>, <span class="function"><span class="params">params</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">            isHover = <span class="literal">true</span></span></span><br><span class="line">            myChart.dispatchAction(&#123;</span><br><span class="line"><span class="javascript">                type: <span class="string">&#x27;downplay&#x27;</span>,</span></span><br><span class="line">                seriesIndex: 0,</span><br><span class="line">                dataIndex: hoverIndex</span><br><span class="line">            &#125;)</span><br><span class="line"></span><br><span class="line">            hoverIndex = params.dataIndex</span><br><span class="line">            myChart.dispatchAction(&#123;</span><br><span class="line"><span class="javascript">                type: <span class="string">&#x27;highlight&#x27;</span>,</span></span><br><span class="line">                seriesIndex: 0,</span><br><span class="line">                dataIndex: hoverIndex</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">        myChart.on(<span class="string">&#x27;mouseout&#x27;</span>, <span class="function"><span class="params">params</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">            isHover = <span class="literal">false</span></span></span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="comment">// 立即执行的轮询器</span></span></span><br><span class="line"><span class="javascript">        <span class="keyword">const</span> setIntervalNow = <span class="function">(<span class="params">fn, time</span>) =&gt;</span> &#123;</span></span><br><span class="line">            fn()</span><br><span class="line"><span class="javascript">            <span class="keyword">return</span> <span class="built_in">setInterval</span>(fn, time)</span></span><br><span class="line">        &#125;        </span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="keyword">const</span> loop = <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">            <span class="keyword">if</span>(isHover) <span class="keyword">return</span></span></span><br><span class="line">            myChart.dispatchAction(&#123;</span><br><span class="line"><span class="javascript">                type: <span class="string">&#x27;downplay&#x27;</span>,</span></span><br><span class="line">                seriesIndex: 0,</span><br><span class="line">                dataIndex: hoverIndex</span><br><span class="line">            &#125;)</span><br><span class="line"></span><br><span class="line">            hoverIndex++</span><br><span class="line"><span class="javascript">            <span class="keyword">if</span>(hoverIndex &gt; dataList.length - <span class="number">1</span>)&#123;</span></span><br><span class="line">                hoverIndex = 0</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            myChart.dispatchAction(&#123;</span><br><span class="line"><span class="javascript">                type: <span class="string">&#x27;highlight&#x27;</span>,</span></span><br><span class="line">                seriesIndex: 0,</span><br><span class="line">                dataIndex: hoverIndex</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        setIntervalNow(loop, 1000)</span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>William Leung
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/lianghuilin/murmur.git/echarts/ECharts%E5%AE%9E%E7%8E%B0%E7%8E%AF%E5%9B%BE%E8%BD%AE%E6%92%AD%E4%BB%A5%E5%8F%8A%E4%BA%8B%E4%BB%B6%E6%8E%A7%E5%88%B6/" title="ECharts实现环图轮播以及事件控制">https://gitee.com/lianghuilin/murmur.git/echarts/ECharts实现环图轮播以及事件控制/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/murmur/ecma_script/ES6%20%E8%AF%A6%E8%A7%A3Set%E5%92%8CWeakSet%E9%9B%86%E5%90%88/" rel="prev" title="ES6 详解Set和WeakSet集合">
                  <i class="fa fa-chevron-left"></i> ES6 详解Set和WeakSet集合
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/murmur/university_notes/Java(1)-%E8%AF%AD%E8%A8%80%E6%A6%82%E8%BF%B0%E4%B8%8E%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/" rel="next" title="计应本的自考笔记(1)-Java语言概述与环境安装">
                  计应本的自考笔记(1)-Java语言概述与环境安装 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">William Leung</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">142k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:09</span>
  </span>
</div>
<div class="busuanzi-count">
    <span id="busuanzi_container_site_uv">
      本站访客数<span id="busuanzi_value_site_uv"></span>人次
    </span>
    <span id="busuanzi_container_site_pv">
        本站总访问量<span id="busuanzi_value_site_pv"></span>次
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/murmur/js/utils.js"></script><script src="/murmur/js/motion.js"></script><script src="/murmur/js/next-boot.js"></script>

  
















  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  

  

</body>
</html>
